package com.zhang.common.util;

import java.util.regex.Pattern;

/**
 * 正则工具类
 */
public class RegexUtil {

    public static final String EMAIL_REGEX = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
    public static final String IDCARD_REGEX = "[1-9]\\d{13,16}[a-zA-Z0-9]{1}";
    public static final String PHONE_REGEX = "(\\+\\d+)?1\\d{10}$";
    public static final String INT_REGEX = "\\d+?";
//    public static final String INT_REGEX = "\\-?[1-9]\\d?";
    public static final String DECIMAL_REGEX = "\\-?[1-9]\\d+(\\.\\d+)?";
    public static final String BIRTHDAY_REGEX = "\\d{4}(\\-)\\d{1,2}\\1\\d{1,2}";

    /**
     * 验证邮箱
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        return Pattern.matches(EMAIL_REGEX, email);
    }

    /**
     * 验证身份证
     * @param idCard
     * @return
     */
    public static boolean checkIDCard(String idCard) {
        return Pattern.matches(IDCARD_REGEX,idCard);
    }

    /**
     * 验证手机号
     * @param phone
     * @return
     */
    public static boolean checkMobile(String phone) {
        return Pattern.matches(PHONE_REGEX,phone);
    }

    /**
     * 验证是否是整数
     * @param num
     * @return
     */
    public static boolean checkInteger(String num) {
        return Pattern.matches(INT_REGEX,num);
    }

    /**
     * 验证浮点数
     * @param decimals
     * @return
     */
    public static boolean checkDecimals(String decimals) {
        return Pattern.matches(DECIMAL_REGEX,decimals);
    }

    /**
     * 验证生日
     * @param birthday
     * @return
     */
    public static boolean checkBirthday(String birthday) {
        return Pattern.matches(BIRTHDAY_REGEX,birthday);
    }

}
